package test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

public class GetRandomChar {
	public static void  getRandomNum(){
		File fl = new File("D://Num//random.txt");
		boolean flag = true;
		int num = 0;
		int end = 0;
		/*OutputStream os = null;
		DataOutputStream dos = null;*/
		FileWriter fw = null;
		BufferedWriter br= null;
		try {
			/*os = new FileOutputStream(fl);
			dos = new DataOutputStream(os);
			dos.writeDouble(12);*/
			fw = new FileWriter(fl);
			br = new BufferedWriter(fw);
			while(flag){
				num = (int)(Math.random() * 1000);
				num = num - 500;
				//dos.writeInt(num);
				br.write(String.valueOf(num) + " ");
				//br.write(" ");
				//System.out.println((int)num);
				if(++end == 1000000){
					flag = false;
				}
			}
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				br.flush();
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void GetChar(){
		File fl = new File("D://Num//randomchar.txt");
		FileWriter fw = null;
		BufferedWriter bw = null;
		boolean flag = true;
		char ch;
		int end = 0;
		try {
			fw = new FileWriter(fl);
			bw = new BufferedWriter(fw);
			while(flag){
				ch = (char)('a' + Math.random() * 26);
				bw.write(ch + " ");
				//br.write(" ");
				//System.out.println((int)num);
				if(++end == 1000000){
					flag = false;
				}
			}
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				bw.flush();
				bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
	public static void getRandomStrings(){
		File fl = new File("D://Num//string.txt");
		FileWriter fw = null;
		BufferedWriter bw = null;
		boolean flag = true;
		String str = "";
		char ch;
		int end = 0;
		int longth;
		
		try {
			fw = new FileWriter(fl);
			bw = new BufferedWriter(fw);
			while(flag){
				longth = (int)(Math.random() * 12 + 1);
				int temp = 0;
				System.out.println("longth: " + longth);
				while(temp < longth){
					ch = (char)('a' + Math.random() * 26);
					str = str + String.valueOf(ch);
					temp++;
				}
				bw.write(str + " ");
				str = "";
				bw.flush();
				if(++end == 1000000){
					flag = false;
				}
			}
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				bw.flush();
				bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args){
		//GetRandomChar.getRandomStrings();
		//GetRandomChar.getRandomNum();
		GetRandomChar.GetChar();
	}
}
